<?php
$javascript->link('inputmask', false);
$javascript->link('sociall.messages.js?v=091117', false);

//debug($messages[0]);
//debug($timeline[0]);
print $form->create('Message', array('action' => 'send'));
?>

<fieldset>
	<div id="mbox">
		<h2 id="wad">
		<?php
			__('What are you doing?');
			print '<span id="chc" class="mh140" title="'.__('Maximum message length on Twitter is 140 characters', true).'">140</span>';
		?>
		</h2>

		<?php
		if($ping = $session->read('ping')){
			//we have a ping to send let the user do it if she wants
			$pingMessage = $ping['message'];
			$pingAccount = $ping['account_id'];
		}

		print $html->image(
						'http://www.gravatar.com/avatar/'.md5(strtolower($session->read('Auth.User.email'))).'.jpg?s=75&d=' . urlencode($html->url('/img/no_avatar.png')),
						array(
							'class' => 'mygravatar',
							'title' => __('Your registered gravatar on http://gravatar.com', true),
							'alt' => 'gravatar',
							'id' => 'mygravatar'
						)
						);
		print $form->input('message', array(
											'type' => 'textarea',
											'value' => isset($pingMessage) ? $pingMessage : false,
											'rows' => 3,
											'cols' => 75,
											'label' => false,
											'div' => false
											));
		print '<div id="sender">';
			print $html->image('ajax-loader.gif',
										  array(
													'id' => 'ajaxloaderSend',
													'style' => 'display: none',
													'alt' => __('Ajax loading indicator', true),
													'title' => __('Sending message', true)
												 )
										  );
			print $form->submit(__('Submit', true),
											array(
												'id' => 'messageSubmit',
												'div' => false
											));
		print '</div>';
		?>
	</div>
	
	<?php
	print '<div id="timed">';
		print $html->image(
						'clock.png',
						array(
							'class' => 'mygravatar',
							'title' => __('Timed messages', true),
							'alt' => __('Timed messages', true),
							'id' => 'timedClock',
							'class' => 'inactive_timed'
						)
						);
		print '<div id="timeBox" style="display: none;">';
			//print $html->image('forward.png');
			print $form->input('date', array(
											'label' => $html->link(__('Time', true), array('controller' => 'timeds', 'action' => 'index'), array('title' => __('View timed messages', true))),
											'div' => false,
											'title' => __('Use yyyy-mm-dd format', true)));
			print $form->input('time', array(
											'label' => false,
											'div' => false,
											'title' => __('Use hh:mm format', true)));
		print '</div>';
	print '</div>';
	?>
	<h3 id="acch"><?php __('Where to send?'); ?></h3>
	<ul id="accs">
	<?php
	$i = 0;
	foreach($accounts as $acc){
		$checked = (isset($pingAccount) && $pingAccount == $acc['Account']['id']) ? true : false;
		$cssClass = $checked ? 'active_logo' : 'inactive_logo';
		print '<li class="fl acc" id="acc_'.($i+1).'">' . $form->input('Account.Account_'.$i,
								 array(
									'value' => $acc['Account']['id'],
									'type' => 'checkbox',
									'checked' => ($checked ? 'checked' : null),
									'label' => $html->image('logo_'.$acc['Community']['name'].'.png',
																	array(
																		'alt' => $acc['Community']['name']  . '::' . $acc['Account']['username'],
																		'title' => $acc['Community']['name']  . '::' . $acc['Account']['username'],
																		'class' => $cssClass,
																		'id' => 'acclogo_' . $i
																		)
																	),
									'div' => false
									)) . '</li>';
		$i++;
	}
	?>
	</ul>
	<?php
	?>
</fieldset>
<?php
print $form->end();

//debug($messages);

print $this->element('timeline', array('timed' => false));
/*print '<div id="timeline">';
foreach($messages as $key => $m){

	print '<div class="entry">';
		print '<div class="logos">';
			foreach($m['Account'] as $acc){
				$error = isset($acc['AccountsMessage']['error']) ? $acc['AccountsMessage']['error'] : null;
				print '<span class="">' . $html->image('logo_'.$acc['Community']['name'].'.png',
							 array(
									 'alt' => $acc['Community']['name'] . '/' . $acc['username'],
									 'title' => $error ? __('Error sending to ', true) . $acc['Community']['name'] . '/' . $acc['username'] : $acc['Community']['name'] . '/' . $acc['username'],
									 'class' => $error ? 'error_logo' : 'active_logo'
									 )
							 ) . '</span>';
			}
		print '</div>';

		$cssClass = ($key % 2) ? 'odd' : '';
		print '<div class="m '.$cssClass.'">';
			if(isset($acc['avatar'])){
				$avatar = $acc['avatar'];
				//print $html->link(
				print $html->image(
											$avatar,
											array(
												'class' => 'mygravatar',
												'alt' => $acc['username'],
												'title' => $acc['username'],
												'height' => 48,
												'width' => 48
											)
			}
			else{
				$avatar = 'http://www.gravatar.com/avatar/'.md5(strtolower($session->read('Auth.User.email'))).'.jpg?s=60&d=' . urlencode($html->url('/img/no_avatar.png'));
				print $html->image(
						$avatar,
						array(
							'class' => 'mygravatar'
						)
						);
			}
			print '<p>';
				print preg_replace('|(http://\S*)|', '<a href="\1" target="_blank">\1</a>', $m['Message']['message']);
			print '</p>';
			print '<p class="mtime">';
				foreach($m['Account'] as $acc){
					//if(isset($acc['url']))
						//print $html->link('@'.$acc['username'], $acc['url'], array('class' => 'mu'), null, false);
					//else
						print '<span class="mu">@'.$acc['username'].'</span>';
				}
				print $m['Message']['created'];
			print '</p>';
		print '</div>';

	print '</div>';
}
print '</div>';*/
?>